<?php
//=======================================
//###################################
// Kayako Web Solutions
//
// Source Copyright 2001-2004 Kayako Web Solutions
// Unauthorized reproduction is not allowed
// License Number: $%LICENSE%$
// $Author: mslaria $ ($Date: 2007/02/27 14:03:32 $)
// $RCSfile: client_lostpassword.php,v $ : $Revision: 1.3 $ 
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
//###################################
//=======================================


if (!defined("INSWIFT")) {
	trigger_error("Unable to process $PHP_SELF", E_USER_ERROR);
}

require_once ("./includes/functions_users.php");
require_once ("./includes/functions_html.php");
$template->loadLanguageSection("lostpassword");

$template->assign("navigation", '<a href="index.php" id="navlink">'.$_SWIFT["language"]["navhome"].'</a> &raquo; <a href="index.php?_m=core&_a=lostpassword" id="navlink">'.$_SWIFT["language"]["llostpassword"]."</a>");

/**
* ###############################################
* SEND VERIFICATION EMAIL
* ###############################################
*/
if ($_REQUEST["do"] == "sendveriemail")
{
	if ($_POST["email"] == "")
	{
		$template->assign("posterror", true);
		unset($_REQUEST["do"]);
	} else {
		// All Ok.
		$userid = getUserEmail($_POST["email"]);
		if (!$userid)
		{
			$template->assign("errormessage", $_SWIFT["language"]["linvalidemail"]);
			unset($_REQUEST["do"]);
		} else {
			$result = sendLostPasswordEmail($userid);
			if (!$result)
			{
				$template->assign("errormessage", $_SWIFT["language"]["linvalidemail"]);
				unset($_REQUEST["do"]);
			} else {
				$template->cache(array('lostpasswordconfirm', 'header', 'footer', 'navbar'));
				$template->assign("backurl", "index.php");
				$template->assign("sectiontitle", $_SWIFT["language"]["llostpassword"]);
				$template->assign("sectiondesc", $_SWIFT["language"]["lpassc_desc"]);
				$template->assign("email", htmlspecialchars($_POST["email"]));
				echo $template->displayTemplate("lostpasswordconfirm");
				exit;
			}
		}
	}




/**
* ###############################################
* DISPLAY THE LOST PASSWORD FORM
* ###############################################
*/
}

if (empty($_REQUEST["do"]))
{
	$template->cache(array('lostpasswordform', 'header', 'footer', 'navbar'));
	$template->assign("backurl", "index.php");
	$template->assign("sectiontitle", $_SWIFT["language"]["llostpassword"]);
	$template->assign("sectiondesc", $_SWIFT["language"]["lpass_desc"]);
	$template->assign("email", htmlspecialchars($_POST["email"]));
	echo $template->displayTemplate("lostpasswordform");
}
?>